package com.zb.order.controller;


import com.zb.annotation.SystemLog;
import com.zb.constant.OperationLogModuleType;
import com.zb.constant.OperationLogType;
import com.zb.entity.SelectVo;
import com.zb.order.service.ConWorkSetService;
import com.zb.result.PageUtil;
import com.zb.result.Result;
import com.zb.service.ZjWorkTeamService;
import com.zb.utils.TokenUtil;
import com.zb.vo.WorkTeamVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 工单客服组表 前端控制器
 * </p>
 *
 * @author WEN
 * @since 2023-09-12
 */
@Api(tags = "工单客服组类接口")
@RestController
@RequestMapping("/work/team")
public class ZjWorkTeamController {
    @Resource
    private ZjWorkTeamService workTeamService;
    @Resource
    private ConWorkSetService conWorkSetService;


    @SystemLog(moduleType = OperationLogModuleType.WORK_ORDER_TYPE, type = OperationLogType.INSERT_UPDATE, remark = "工单管理-工单设置-工单策略-工单客服组 - 新增或修改工单客服组")
    @ApiOperation("新增或修改工单客服组")
    @PostMapping("/save")
    public Result save(HttpServletRequest request, @RequestBody @Valid WorkTeamVo workTeamVo) {
        Long custaccId = TokenUtil.getcustAccIdByToken(request);
        workTeamService.save(custaccId, workTeamVo);
        return Result.success(null == workTeamVo.getId()? "新增客服组成功" : "修改客服组成功");
    }

    @ApiOperation("获取客服组列表")
    @PostMapping("/getList")
    public Result getList(HttpServletRequest request, @RequestBody SelectVo selectVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        return Result.success("获取客服组列表成功").data(conWorkSetService.getList(custAccId, selectVo));
    }

    @ApiOperation("根据客服组ID获取客服组详情")
    @GetMapping("/getDetail/{id}")
    public Result getDetail(@PathVariable @ApiParam(value = "客服组ID", required = true) Long id) {
        return Result.success("获取客服组详情成功").data("row", workTeamService.getDetail(id));
    }

    @SystemLog(moduleType = OperationLogModuleType.WORK_ORDER_TYPE, type = OperationLogType.UPDATE, remark = "工单管理-工单设置-工单策略-工单客服组 - 根据客服组ID集合批量启用或禁用客服组")
    @ApiOperation("根据客服组ID集合批量启用或禁用客服组")
    @PutMapping("/disable")
    public Result disable(@RequestParam @ApiParam(value = "客服组状态：false-启用，true-禁用", required = true, example = "false") boolean status,
                          @RequestBody @ApiParam(value = "客服组ID集合", required = true) List<Long> idList) {
        workTeamService.updateDisabledBatchById(idList, status);
        return Result.success(status? "禁用客服组成功" : "启用客服组成功");
    }

    @SystemLog(moduleType = OperationLogModuleType.WORK_ORDER_TYPE, type = OperationLogType.DELETE, remark = "工单管理-工单设置-工单策略-工单客服组 - 根据客服组ID集合批量删除客服组")
    @ApiOperation("根据客服组ID集合批量删除客服组")
    @DeleteMapping("/delete")
    public Result delete(HttpServletRequest request, @RequestBody @ApiParam(value = "客服组ID集合", required = true) List<Long> idList) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        workTeamService.deleteBatchById(custAccId, idList);
        return Result.success("删除客服组成功");
    }



}
